<?php

/**
 * main.php
 *
 * This file holds frontend configuration settings.
 */
$frontendConfigDir = dirname(__FILE__);

$params = require_once($frontendConfigDir . DIRECTORY_SEPARATOR . 'params.php');

// Setup some default path aliases. These alias may vary from projects.
Yii::setPathOfAlias('root', ROOT);
Yii::setPathOfAlias('common', ROOT . DIRECTORY_SEPARATOR . 'common');
Yii::setPathOfAlias('backend', ROOT . DIRECTORY_SEPARATOR . 'backend');
Yii::setPathOfAlias('www', ROOT . DIRECTORY_SEPARATOR . 'frontend' . DIRECTORY_SEPARATOR . 'www');

$mainLocalFile = $frontendConfigDir . DIRECTORY_SEPARATOR . 'main-local.php';
$mainLocalConfiguration = file_exists($mainLocalFile) ? require($mainLocalFile) : array();

$mainEnvFile = $frontendConfigDir . DIRECTORY_SEPARATOR . 'main-env.php';
$mainEnvConfiguration = file_exists($mainEnvFile) ? require($mainEnvFile) : array();

return CMap::mergeArray(
                array(
            // @see http://www.yiiframework.com/doc/api/1.1/CApplication#basePath-detail
            'basePath' => $frontendConfigDir . DIRECTORY_SEPARATOR . '..',
            // set parameters
            'params' => $params,
            // preload components required before running applications
            // @see http://www.yiiframework.com/doc/api/1.1/CModule#preload-detail
            'preload' => array('bootstrap', 'log'),
            // @see http://www.yiiframework.com/doc/api/1.1/CApplication#language-detail
            'language' => 'en',
            // uncomment if a theme is used
            /* 'theme' => '', */
            // setup import paths aliases
            // @see http://www.yiiframework.com/doc/api/1.1/YiiBase#import-detail
            'import' => array(
                'common.components.*',
                'common.components.helpers.*',
                'common.models.*',
                'common.models.user.*',
                'common.models.object.*',
                'common.models.emailtemplate.*',
                'application.components.*',
                'application.controllers.*',
                'application.models.*'
            ),
            /* uncomment and set if required */
            // @see http://www.yiiframework.com/doc/api/1.1/CModule#setModules-detail
            /* 'modules' => array(), */
            'components' => array(
                'user' => array(
                    // enable cookie-based authentication
                    'allowAutoLogin' => true,
                    'class' => 'WebUser'
                ),
                /* load bootstrap components */
                'bootstrap' => array(
                    'class' => 'common.extensions.bootstrap.components.Bootstrap',
                    'coreCss' => true,
                    'yiiCss' => false,
                    'jqueryCss' => false
                ),
                'errorHandler' => array(
                    // @see http://www.yiiframework.com/doc/api/1.1/CErrorHandler#errorAction-detail
                    'errorAction' => 'site/error'
                ),
                'db' => $params['db.connect'],
                'urlManager' => array(
                    'urlFormat' => 'path',
                    'showScriptName' => false,
                    'urlSuffix' => '',
                    'rules' => $params['url.rules']
                ),
                'settings' => $params['settings'],
                'cache' => $params['cache.file'],
                'log' => array(
                    'class' => 'CLogRouter',
                    'routes' => array(
                        //array(
                        //'class' => 'CFileLogRoute',
                        //'levels' => 'error, warning',
                        //),
                        // uncomment the following to show log messages on web pages
                        array(
                            'class' => 'CWebLogRoute',
                            'levels' => 'trace, info, error, warning',
                        ),
                    ),
                ),
                'Paypal' => $params['Paypal'],
                // get format detail
                'format' => $params['format']
            /* make sure you have your cache set correctly before uncommenting */
            /* 'cache' => $params['cache.core'], */
            /* 'contentCache' => $params['cache.content'] */
            ),
            'modules' => array(
                'gii' => array(
                    'class' => 'system.gii.GiiModule',
                    'password' => false,
                    'generatorPaths' => array(
                        'bootstrap.gii'
                    ),
                ),
            )
                ), CMap::mergeArray($mainEnvConfiguration, $mainLocalConfiguration)
);